package cn.rui.pojo.exam;

import cn.rui.pojo.User;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author 徽州大都督
 * @date 2021/6/25
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "随机组卷实体类", value = "随机组卷实体类")
@TableName("sys_paper")
public class Paper implements Serializable {

    @TableId(type = IdType.AUTO)
    private Long id;

    //试卷名称
    private String paperName;

    //创建人
    private Integer userId;

    //创建人实体
    @TableField(exist = false)
    private User user;

    //单选题数量
    private Integer radioNum = 0;

    //单选题分数
    private Integer radioScore = 0;

    //多选题数量
    private Integer multiNum = 0;

    //多选题分数
    private Integer multiScore = 0;

    //判断题数量
    private Integer judgeNum = 0;

    //判断题分数
    private Integer judgeScore = 0;

    //简单题数量
    private Integer shortAnswerNum = 0;

    //简答题分数
    private Integer shortAnswerScore = 0;

    //开始考试时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date startCheck;

    //总分
    private Integer grandScore;

    //开始考试时间字符串
    @TableField(exist = false)
    private String startCheckStr;

    //考试时长 单位分钟
    private Integer checkTime;

    private Boolean status;

    //1随机  2手动
    private Integer paperType;

    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @TableLogic
    private Integer delFlag;

    @Ignore
    public Integer getGrandScore() {
        return this.grandScore = this.radioScore * this.radioNum + this.multiNum * this.multiScore + this.judgeNum * this.judgeScore + this.shortAnswerNum * this.shortAnswerScore;
    }

    @TableField(exist = false)
    private List<ExamQuestion> questions;

    //已经参加此试卷的学生id集合
    @TableField(exist = false)
    private List<Integer> testUserIds;

    @TableField(exist = false)
    private UserAnswer userAnswer;
}
